views:

30

answers:

2

Hi there, I have a link, that when a user clicks on it, it loads a different page as normal but also executes a JS function that autofills a specific text-box on that different page. Is it better practice to use Jquery or Javascript to do this? How can I do this using either one of them?

+1  A: 

At the end of the script add return false;. This will make the page run the script without redirecting the page.

Edit: (after saw your edition).

Is it better practice to use Jquery or Javascript to do this? How can I do this using either one of them?

jQuery is a javascript library, this it doesn't matter if you use plain javascript or use jquery as long as you happy with the result.

And about what you say that you successfully manipulated a page fro the redirecter page... I don't see how it possible.

Mendy
sorry I was unclear, the link is going to an external page
Alex
this is not want I want to do, but your answer is my fault for asking such a horribly formatted quesiton. I have since revised it. My apologies. :)
Alex
+1  A: 

You can't do this from the source page.

It's a security feature. Imagine if you wrote a JS function that went to an online banking page and auto-filled a bank transfer using the user's current cookie. That's why you can't.

If you control the other page then the sequence you can use is:

  • Save data to the server;
  • Go to the new page with a JS redirect;
  • The new page is loaded from the server;
  • While loading th epage the data that was saved from the server is retrieved and used to populate the text box.

So it can be done from the server but only if you save it there. The only way of doing that is using Ajax.

An alternative approach is:

  • Instead of a JS redirect, submit the page back to the server;
  • The server saves whatever data it needs to;
  • The server sends back an HTTP redirect to the new page;
  • The new page uses the saved data to construct the new page with the populated text box.
cletus
yes, maybe looking at this question will help you understand what I want to do? You are being really helpful, but I'm not sure if what you are explaining is what I want to do. The question: http://meta.stackexchange.com/questions/4722/can-i-auto-tag-a-question
Alex
I guess since we use stackexhange, then this is not even remotely possible anyway?
Alex