LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-05-2017, 08:17 PM   #1
pizzipie
Member
 
Registered: Jun 2005
Location: Hayden, ID
Distribution: Ubuntu 20.04
Posts: 441

Rep: Reputation: 12
form not allowing input


I'm trying to combine Radio inputs and text inputs in the same form.
If I click on the radio buttons the input is as expected.

If I try to use the text input the function fires without allowing any input .

Do I need two forms to fix this? Input scree shown in attachment.



Code:
<div id="pickIt">

<form action="#" method="GET">

	Choose Camera Directory:<br><br>
	
	<input type="radio" name="photo" id="pana" value='pana'> PANASONIC DCM-215<br>
 	<input type="radio" name="photo" id="canon" value="canon"> CANON SD 1000<br><br>
 	
  	
    	___________  OR  _________<br><br>	
	Enter Base Directory To Access Photos: <br><br>
	<input type="text" id="inputDir">
 
</form>

</div>
<!-- ==============   body scripts 1 of 1   ================ -->

<script type="text/javascript">

$(function(){  // ready

var dir="";
var camera="";

$("#inputDir").on('change', function () {
dir=$(this).val();
myAjaxCall(dir);
});

 $("#pickIt").on('click', function(event) {;
		var choice= $("input[type=radio]:checked").val();			 
	if (choice=="pana") {
		camera="pana";
	}
	if (choice=="canon") {
		camera="canon";		
	}
		myAjaxCall(camera);
  }); // pickIt
Attached Thumbnails
Click image for larger version

Name:	Selection_004.png
Views:	11
Size:	13.5 KB
ID:	25383  
 
Old 07-05-2017, 11:54 PM   #2
hydrurga
LQ Guru
 
Registered: Nov 2008
Location: Pictland
Distribution: Linux Mint 21 MATE
Posts: 8,048
Blog Entries: 5

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
I don't know much about this, but your jQuery is executing a function when there is a click event on the element with id=#pickIt. This element covers the whole form. If you're clicking on the input text field to enter data, that counts as a click and thus the event is triggered. Check by tabbing to the field rather than clicking on it.

A reasonable way of getting round this would be to encapsulate the radio buttons in their own div element, and check for clicks on the id of this specific element.

If this is completely off the mark, I'll gladly delete this comment.
 
Old 07-06-2017, 04:21 AM   #3
scasey
LQ Veteran
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.9.2009
Posts: 5,727

Rep: Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211Reputation: 2211
Not off the mark at all, hydrurga. My first thought on reading the post was that the form does exactly what it's programmed to do.

I'm not a big fan of "automatically" submitting forms. A form should have a "Go" button
Code:
 <input type="submit" value="Submit">
to cause the action. Note that this won't require any javascript coding. Clicking on the Submit will action the form.

There are challenges in mixing radio buttons OR text input, tho. radio buttons cause a "select only one" function automatically. Adding the text input allows the user to choose one of the pre-filled options and enter a directory.

Suggest using a drop-down list box instead of radio buttons, with three options:
Code:
 <select name="photo">
  <option value="">-- Select One --</option>
  <option value="pana">PANASONIC DCM-215</option>
  <option value="canon">CANON SD 1000</option>
  <option value="base">Enter Base Directory To Access Photos</option>
</select>
Then only use the text in the <input type="text" id="inputDir"> if the "Enter Base Directory..." (photo = base) is selected. Otherwise, simply ignore anything in that field.
One would probably need to validate that something is in the field if base is selected.

Just a thought.

Last edited by scasey; 07-06-2017 at 09:09 AM.
 
Old 07-06-2017, 12:05 PM   #4
pizzipie
Member
 
Registered: Jun 2005
Location: Hayden, ID
Distribution: Ubuntu 20.04
Posts: 441

Original Poster
Rep: Reputation: 12
Thank you both,


Quote:
A reasonable way of getting round this would be to encapsulate the radio buttons in their own div element, and check for clicks on the id of this specific element.
hydrurga, I put the radio buttons in a <div> and all is well.

R
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
HTML, form input onclick does not work mdooligan Programming 3 03-20-2015 11:05 AM
[SOLVED] HTML POST form gets 403 with certain characters in input Snark1994 Programming 4 05-30-2012 11:35 AM
save input from an online form to a file/database? portia Programming 4 01-30-2010 09:22 AM
csh: variable input of the form x.y.z not accepted kpachopoulos Programming 1 07-24-2005 04:39 PM
(PHP) Stopping Malicious Form Input Obi Perrin Programming 0 04-27-2003 07:43 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration