Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

citizenzen

macrumors 68000
Original poster
Mar 22, 2010
1,543
11,788
I'm a graphic designer who dabbles in web development (noob). I am creating an HTML form that includes PHP and Javascript. I have a pull-down menu that passes a variable to the url so I can dynamically insert content based upon the pull-down choice.

My problem: the pull-down is located far enough down the page so that when a selection is made the page jumps up to the top. I can add a #foo to the URL to prevent the page jump, but then the variable no longer is recognized by my PHP. Alternatively, I can remove the #foo from the URL and gets a variable that passes, but a jumpy page.

Here's my code...

print "<select name=\"paperTypeSelect\" onchange=\"window.open(this.options[this.selectedIndex].value,'_top')\">";
switch ($paperTypeSelect)
{
case (isset($_GET["paper"])):
print "<option value=\"$paperType\" value=\"workRequest.php?function=jobSpecs&paper=$paperType\">$paperType</option>";
break;
default:
print '<option value="">Choose Text or Cover Weight...</option>';
break;
}
print '<option value="workRequest.php?function=jobSpecs&paper=text">Text</option>';
print '<option value="workRequest.php?function=jobSpecs&paper=cover">Cover</option>';
print '<option value="workRequest.php?function=jobSpecs&paper=ncr">NCR</option>';
print '</select>';
print '<br />';
switch ($paperType) {
case ($paperType == 'text'):
print 'x';
break;
case ($paperType == 'cover'):
print 'y';
break;
case ($paperType == 'ncr'):
print 'z';
break;
default:
print '';
break;

 
Look into AJAX, it would be your best bet, that way the page will not to reload. Using a JavaScript library will be the easiest way to make use of AJAX from your standpoint. jQuery would be a recommendation for that.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.