How do I pass 2 document value variables into a submit button?

Discussion in 'JavaScript' started by illectronic, Oct 5, 2013.

  1. #1
    I am trying to submit a date range which is populated correctly in 2 input's.
    How would I go about refreshing the page so I can use GET variables with those 2 date ranges?
    Here is what I have so far. It's in php but it's just echoing. Thanks

    echo "Start date: <input type='text' id='datepickerstart'>";
    echo "End Date: <input type='text' id='datepickerend'>";
    echo "Submit : <input type='submit' id='submitdate' name='test' value='Submit' onSubmit=\"document.location='main.php?page=$page&OWNER=$OWNER&CONTROL_ID=$CONTROL_ID&STATUS=$STATUS&START_DATE='+document.getElementById('datepickerstart').value';&END_DATE='+document.getElementById('datepickerend').value;'\">";
    echo "</form>";
    PHP:

     
    illectronic, Oct 5, 2013 IP
  2. ApocalypseXL

    ApocalypseXL Notable Member

    Messages:
    6,095
    Likes Received:
    103
    Best Answers:
    5
    Trophy Points:
    240
    #2
    Since your asking for this in the JS forum my suggestion is that you use AJAX to call in your PHP file that does the submitting.
     
    ApocalypseXL, Oct 5, 2013 IP
  3. illectronic

    illectronic Greenhorn

    Messages:
    46
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #3
    I figured it out. Quick and dirty but works.
    echo "<input type='button' id='submitdate' name='test' value='Submit' onClick=\"document.location='main.php?page=$page&OWNER=$OWNER&CONTROL_ID=$CONTROL_ID&STATUS=$STATUS&START_DATE='+document.getElementById('datepickerstart').value+'&END_DATE='+document.getElementById('datepickerend').value;\">";
    
    Code (markup):
     
    illectronic, Oct 5, 2013 IP
  4. ApocalypseXL

    ApocalypseXL Notable Member

    Messages:
    6,095
    Likes Received:
    103
    Best Answers:
    5
    Trophy Points:
    240
    #4
    No all you need to do is refactor it into something less dirty.
     
    ApocalypseXL, Oct 5, 2013 IP
  5. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #5
    Given the fields presented, my advice is to swing an axe at the javascript nonsense -- but again if you can't make your form work without scripting FIRST, you have no business adding scripting to it.
     
    deathshadow, Oct 6, 2013 IP
  6. illectronic

    illectronic Greenhorn

    Messages:
    46
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #6
    I'd like to hear a better alternative of passing get variables from 2 input boxes without using javascript. Not tryning to be rude, just trying to learn.
     
    illectronic, Oct 6, 2013 IP
  7. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #7
    Pretty simple to not use scripting -- that's what ACTION and INPUT[hidden] are for. I set it to use isset so that if that getDATA exists when the form is sent, they are plugged in for values. (which I think is what you were actually asking...)

    echo '
    	<form action="main.php" method="get">
    		<fieldset>
    			<label for="datePickerStart">Start date:</label>
    			<input type="text" id="datePickerStart" name="START_DATE"',(
    				isset($_GET['START_DATE']) ? ' value="'.$_GET['START_DATE'].'"' : ''
    			),' />
    			<br />
    			<label for="datePickerEnd">End Date:</label>
    			<input type="text" id="datePickerEnd" name="END_DATE"',(
    				isset($_GET['END_DATE']) ? ' value="'.$_GET['END_DATE'].'"' : ''
    			),' />
    			<br />
    			<input type="submit" value="Submit" />
    			<input type="hidden" name="page" value="',$page,'" />
    			<input type="hidden" name="OWNER" value="',$OWNER,'" />
    			<input type="hidden" name="CONTROL_ID" value ="',$CONTROL_ID,'" />
    			<input type="hidden" name="STATUS" value="',$STATUS,'" />
    		</fieldset>
    	</form>';
    Code (markup):
    Functionally identical to your initial post, no javascript needed.... also helps to not say echo a dozen times when you don't have to.
     
    deathshadow, Oct 6, 2013 IP
  8. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #8
    BTW -- where did you get the idea you needed to use javascript for what you were doing in the first place? Literally that was some genuine bizzaroland code.
     
    deathshadow, Oct 7, 2013 IP