Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    May 2005
    Posts
    262
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Form value to query string

    Hello,

    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?

    Example:


    Code:
    <form name=testform><input type=text name=date value="2006-07-05"></form>


    now for my link

    Code:
    <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.

  • #2
    Regular Coder
    Join Date
    Sep 2005
    Posts
    535
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'd first create an ID for the <input> element and then use DOM to get the value when the link is pressed:
    Code:
    <form name="testform">
      <input type="text" name="date" id="date" value="2006-07-05">
    </form>
    ...
    <a href="NoJSPage.html" onclick="popup('../temp/mypage.php?date=' + document.getElementById('date').value);">
      Check for conflicts
    </a>
    (I also added partial code to allow link to degrade gracefully if person doesn't have JS running for your page...)
    If you want answers, write a smart question.

    Yes, someone probably does know how...

    Oh, and if you want to learn, STFW!

  • #3
    Regular Coder
    Join Date
    May 2005
    Posts
    262
    Thanks
    4
    Thanked 0 Times in 0 Posts
    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

    Code:
    <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

    Code:
     
    <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.
    Last edited by tripwater; 07-06-2006 at 05:02 PM.

  • #4
    Regular Coder
    Join Date
    Sep 2005
    Posts
    535
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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')[0] would refer to your first button whereas getElementsByName('repeat_type_one')[1] would refer to the second.
    If you want answers, write a smart question.

    Yes, someone probably does know how...

    Oh, and if you want to learn, STFW!

  • #5
    Regular Coder
    Join Date
    May 2005
    Posts
    262
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Thanks. I get it. But if I call
    Code:
    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
    Code:
    getElementsByName('repeat_type_one')[0]
    would refer to the first radio and
    Code:
    getElementsByName('repeat_type_one')[1]
    refers to the second radio then should
    Code:
    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
    Code:
    &repeat=radiovalue
    to my popup

    thanks again.
    Last edited by tripwater; 07-06-2006 at 08:56 PM.

  • #6
    Regular Coder
    Join Date
    Sep 2005
    Posts
    535
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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!
    If you want answers, write a smart question.

    Yes, someone probably does know how...

    Oh, and if you want to learn, STFW!

  • #7
    Regular Coder
    Join Date
    May 2005
    Posts
    262
    Thanks
    4
    Thanked 0 Times in 0 Posts
    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.

  • #8
    Regular Coder
    Join Date
    May 2005
    Posts
    262
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Question

    Sorry, Posted another question and I should have posted this somewhere else...EDITED
    Last edited by tripwater; 07-21-2006 at 05:17 PM. Reason: Posted in wrong place


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •