View Full Version : Form value to query string
07-05-2006, 03:46 PM
If I have a form element that I need to pass whatever value is typed into it to a link so that when it is clicked, it can tell a popup to do something with the server without leaving the page, how would I do this?
<form name=testform><input type=text name=date value="2006-07-05"></form>
now for my link
<a href="" popup(../temp/mypage.php?date=2006-07-05);>Check for conflicts</a>
I just need to do some server work before leaving the page and let the user interact and make some last minute decisions before posting so I need to give them the ability to pull up a page and see if there are conflicts and select which ones to ignore. but I need the date they enter into the form to be passed to my popup and if they change the date in the form and click the link again, obviously run a new check for the new date.
thank you for any help with this.
07-05-2006, 06:46 PM
I'd first create an ID for the <input> element and then use DOM to get the value when the link is pressed:
<input type="text" name="date" id="date" value="2006-07-05">
<a href="NoJSPage.html" onclick="popup('../temp/mypage.php?date=' + document.getElementById('date').value);">
Check for conflicts
(I also added partial code to allow link to degrade gracefully if person doesn't have JS running for your page...)
07-06-2006, 04:56 PM
Thank you very much! that works like a charm.
I now realized I needed to add the result from a radio box being checked as well. I tried using the same setup as you have by setting both radio boxes to the same ID so whichever one is checked, it will pass the value over as well but I keep getting 1 no matter what.
so My radio buttons are like
<input type radio name=repeat_type_one id=repeat_type value=1> Daily
<input type radio name=repeat_type_one id=repeat_type value=2> Weekly
and I tried to add this to my query string
<a href="" onclick="return popup('mypage.php?fromdate=' + document.getElementById('fromdate').value + '&todate=' + document.getElementById('todate').value + '&repeat=' + document.getElementById('repeat_type').value);">Check for Conflicts</a>
THank you again for your time and any additional help with this.
07-06-2006, 08:38 PM
You've just found the difference between id's and names; id's are unique for each element (if you use the same id for multiple elements, depending on browser, only the first element will actually have that attribute). You might try getElementsByName() (notice the plural spelling! ). This will return a collection of all elements with the same name. Thus getElementsByName('repeat_type_one') would refer to your first button whereas getElementsByName('repeat_type_one') would refer to the second.
07-06-2006, 08:51 PM
Thanks. I get it. But if I call
getElementsByName() in a set of radio buttons will it just return the value of the one that is checked? Because I really just need to know that. If I am dealing with an array of results, would I not then need to loop through checking?
Just want to be sure because if
getElementsByName('repeat_type_one') would refer to the first radio and
getElementsByName('repeat_type_one') refers to the second radio then should
getElementsByName('repeat_type_one') not just return the value of the one that is checked (true). I tried this and I get 'undefined' as what my query string holds in my popup.
Ultimately I just need the value of which ever one is checked in the group to be setup to pass over the var as
&repeat=radiovalue to my popup
07-07-2006, 01:43 PM
Use process of elimination. If the buttons are mutually exclusive (one and only one can be checked at any time) then just send the value of the first button. If the value is true, then the first is checked, otherwise the second must be checked.
If you have more than one button, then you will indeed have to loop through the buttons to find the correct one. If you do need to loop through it, make sure you use a regular for-loop and not a for...in-loop as this loops through the properties of an object and not the objects in a collection!
07-07-2006, 04:30 PM
Thank you for your help Pyth007.
I just created a JS function that checked which was checked and returned the value and called the function inline with query string. Sorry for being lazy...not much sleep lately :)
Thank you again for your time.
07-21-2006, 05:05 PM
Sorry, Posted another question and I should have posted this somewhere else...EDITED
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.