2 Replies - 3933 Views - Last Post: 20 October 2011 - 11:41 PM

#1 CarDriver  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 65
  • View blog
  • Posts: 431
  • Joined: 17-February 11

How do I make a form that doesn't switch pages?

Posted 20 October 2011 - 03:53 PM

I'm new to Javascript, and I don't know how I should create HTML forms that don't redirect to a different page. I'm planning on making an application that lets you create a quiz and take it with as many questions as you want (using loops and arrays). I've done this in a number of languages, including Javascript, but I don't know how to tie this in to HTML so I don't have a web app that relies on pop-ups as the UI.

When you make a form, it asks for the action, which should be a different page. It then redirects to this page if a button is clicked, for instance. Given the nature of this quiz program that can theoretically create more questions than I have the ability to make separate web pages for, how do I do this? I don't plan on making 1,000 different pages with nearly identical code; this is what the loop is for.

<form name="UsernameForm" action="I don't want it to change the page" method="post">
Username: <input type="text" name="username" />
<input type="submit" value="Submit" />
</form>



I want to stay on one page and have values changed around a bit. Would this be possible with Javascript or should I use PHP or ASP.NET & C#?

Thanks!

Edit: You know, this was a stupid question. I guess it redirects to the same page if no action is given, which will probably work for my purposes. Anyway, it would be nice if it didn't have to redirect and all, but this will still work, I believe. You can disregard this.

This post has been edited by AVReidy: 20 October 2011 - 04:18 PM


Is This A Good Question/Topic? 0
  • +

Replies To: How do I make a form that doesn't switch pages?

#2 sas1ni69  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 85
  • View blog
  • Posts: 431
  • Joined: 04-December 08

Re: How do I make a form that doesn't switch pages?

Posted 20 October 2011 - 05:21 PM

Hi there, don't worry it's not a stupid question. What you want to be looking at is AJAX. Asynchronus Javascript and XML.

It allows you to submit the form and to retrieve the information without loading the entire page. There are several tutorials about this in the tutorial section.
Was This Post Helpful? 0
  • +
  • -

#3 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3569
  • View blog
  • Posts: 10,402
  • Joined: 08-June 10

Re: How do I make a form that doesn't switch pages?

Posted 20 October 2011 - 11:41 PM

View PostAVReidy, on 21 October 2011 - 12:53 AM, said:

Edit: You know, this was a stupid question. I guess it redirects to the same page if no action is given,

a very insecure way of relying on the browser to fix invalid HTML (the formís action attribute is required, i.e. you must not omit it). however, in most cases you know what the name of the current file is, so you just can write that in there.

but as already been mentioned, look into AJAX for your scenario
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1