Skip to content Skip to sidebar Skip to footer

Page Redirection

I'm working on a script where all I want it to do (right now) is redirect the user based on which button they press. Eventually it will take form input and incorporate that into t

Solution 1:

You want to use a button not an input type='submit'. Your current buttons are submitting the form, not performing their onclick actions.

Or block the submit action in some way. Or you could use your functions to set the form action to the url and just let it submit.

Solution 2:

Your scripts seem highly overcomplicated. Why not have three functions: getQ, googleSearch, and youTubeSearch? Then inside the onClick event you can call the exact function, including this.value inside the input parameters and calling getQ from inside that function? Your method seems highly inefficient. If you're going to have separate functions for each of them anyways, there's no use in going through two other functions in order to get to them.

A submit button will always submit the form without a return false at the end of the onClick event, and since the default posting method is GET, its attaching ?q= to the end of your URL because that field is blank and it's the only input field in the form.

Solution 3:

For redirecting to new page you no need to use the big javascript function.

<html><body><inputtype="button"value="Google Search"onclick="javascript:window.location.href='http://www.google.com'" /><inputtype="button"value="You tube Search"onclick="javascript:window.location.href='http://youtube.com'" /></body></html>

Please check whether it helps you.

Solution 4:

Well as jasonbar says, change your input to be of type 'button' and not 'submit'. Plus, I'd rather use window.location.href instead of window.location only. I don't know possible this is good practice...happy programming.

Post a Comment for "Page Redirection"