Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

form question 1

Status
Not open for further replies.

axman505

Technical User
Jun 20, 2001
489
US
I have the following html form:

Code:
<form method='get' action='javascript:openwindow("lookup.php")'>
User Lookup: <input type='text' name='username' size='10' maxlength='25' />
<input type='submit' value='GO!' />
</form>

What i want, is that when this form is subbmitted, it will open in a popup window. THe way it is above, it will open, but none of the paremeters are getting passed. Is there a better way to do this?

Thanks,

Aaron
 

Code:
<form method='get' action='lookup.php' target='_blank'>
User Lookup: <input type='text' name='username' size='10' maxlength='25' />
<input type='submit' value='GO!' />
</form>

*cLFlaVA
----------------------------
Breaking the habit...
 
Is that valid XHTML 1.0 strict? Target is a depreciated tag.
 
You can try something like this.

Code:
<head>

<script Language="JavaScript">

function letsDoIt() {
  var userNameData = document.myForm.username.value;
  var urlRef = "lookup.php?username=" + userNameData;
  var myWindow = window.open(urlRef);
  myWindow.focus();
}

</script>

</head>
<body>

<form name='myForm'>
User Lookup: <input type='text' name='username' size='10' maxlength='25' />
<input type='button' value='GO!' onClick='letsDoIt();'/>
</form>
</body>

I use the myWindow.focus(); statement at the end just in case the window gets minimized and someone presses the GO! button again. The focus() statement will bring the window back up to the surface.

ToddWW
 
Thanks for that chunk of code, it works. The only problem i have now, is that i have to click the Go button for it to work. If i hit enter, nothing happens. Is there an easy fix to this?
 
Please provide me with a link to a webpage that describes when/why target became a deprecated attribute.

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
Read the XHTML 1.0 Strict standards. Target is a depreciated attribute.
 
Ehh, now I'm getting some pages that contradict. I'm sure you're correct.

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
It is one of the attributes that is valid in XHTML 1.0 Transitional, but when you move to Strict, it is not valid.

If you want to test for yourself, make a simple page with a form, add the target attribute and validate it agaisnt the w3c.
 
I believe you. Why would they deprecate that though, leaving no way to submit a form to a new page other than the terrible parsing and JavaScript solution above? It doesn't make much sense to me...

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
I think they are trying to make our life difficult. For example, if you wish to have a regular link open in a new window, the proper way to do it now is:

Code:
<a href="[URL unfurl="true"]www.google.com"[/URL] onclick="window.open(this.href,'_blank');return false;">Google</a>
 
Interesting. Thanks for the info. When will xhtml be taking over the world?

*cLFlaVA
----------------------------
Lois: "Peter, you're drunk!"
Peter: "I'm not drunk, I'm just exhausted from stayin' up all night drinking!
 
Meanwhile...

In your FORM tag, try:

onSubmit='letsDoIt();return false;'

This should let you hit enter and run that function.

--Dave
 
XHTML 1.0 Strict got flamed a lot for deprecating target attribute. Their explanation made sense, though it is very radical. HTML code does not affect browser behaviour, only page behaviour. Target attribute launched another browser which could cause confusion to users not paying attention to what is happening on their screen (new browser no longer has back button available). That is why target was dropped, though there were discussions that it will be back in XHTML 2.0. Strictly speaking, W3 was right to omit it. We use Javascript to mess with client's browser, not HTML.
 
Actually, the target attribute is valid, just not in the default doctype. Modular doctypes allows you to add it in yourself so that your page validates 1.0 Strict.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top