append textbox value to href link before submit

P

pt36

Hi

I have a page with a form and a textbox.
before to submit the form I want to chek if the inserted value in the
textbox is already present in a database.
So I need to pass the textbox value by a javascript link to another
page to check.
my code is
<a href="javascript:location.href='page_check.php' "> Go check </a>
and this work and open page_check.php

but when I want to append the textbox value, the code not work. I know
I make mistake

<a href="javascript:location.href='page_check.php?Box=' +
document.formName.textboxName.value "> Go check </a>

Any suggest ?
Regards
 
D

Doug Gunnoe

Hi

I have a page with a form and a textbox.
before to submit the form I want to chek if the inserted value in the
textbox is already present in a database.
So I need to pass the textbox value by a javascript link to another
page to check.
my code is
<a href="javascript:location.href='page_check.php' "> Go check </a>
and this work and open page_check.php

but when I want to append the textbox value, the code not work. I know
I make mistake

<a href="javascript:location.href='page_check.php?Box=' +
document.formName.textboxName.value "> Go check </a>

Any suggest ?
Regards

this:

<html>
<head>
<script>
function changeURL(){
var lnk = document.getElementById('somelink');
lnk.href = lnk.href + "?" + document.getElementById('txtbx').value;
}
</script>
</head>
<body>
<input type="text" value="" id="txtbx" />
<a href="some_file.html" id="somelink"><input type="button"
value="Check it" onmousedown="changeURL();" /></a>
</body>
</html>

Or, I think this one is better:

<html>
<head>
<script>
function changeURL(){
window.location = "some_file.php" + "?" +
document.getElementById('txtbx').value;
}
</script>
</head>
<body>
<input type="text" value="" id="txtbx" />
<input type="button" value="Check it" onmousedown="changeURL();" />
</body>
</html>
 
D

Doug Gunnoe

Hi

I have a page with a form and a textbox.
before to submit the form I want to chek if the inserted value in the
textbox is already present in a database.
So I need to pass the textbox value by a javascript link to another
page to check.
my code is
<a href="javascript:location.href='page_check.php' "> Go check </a>
and this work and open page_check.php

but when I want to append the textbox value, the code not work. I know
I make mistake

<a href="javascript:location.href='page_check.php?Box=' +
document.formName.textboxName.value "> Go check </a>

Any suggest ?
Regards

you can try this:

<html>
<head>
<script>
function changeURL(){
var lnk = document.getElementById('somelink');
lnk.href = lnk.href + "?" + document.getElementById('txtbx').value
}
</script>
</head>
<body>
<input type="text" value="" id="txtbx" />
<a href="some_file.php" id="somelink"><input type="button"
value="Check it" onmousedown="changeURL();" /></a>
</body>
</html>

or, I think this is better:

<html>
<head>
<script>
function changeURL(){
window.location = "some_file.php" + "?" +
document.getElementById('txtbx').value;
}
</script>
</head>
<body>
<input type="text" value="" id="txtbx" />
<input type="button" value="Check it" onmousedown="changeURL();" />
</body>
</html>
 
T

Thomas 'PointedEars' Lahn

Doug said:
Or, I think this one is better:

Better in which regard?
<html>
<head>
<script>
function changeURL(){
window.location = "some_file.php" + "?" +
document.getElementById('txtbx').value;
}
</script>
</head>
<body>
<input type="text" value="" id="txtbx" />
<input type="button" value="Check it" onmousedown="changeURL();" />
</body>
</html>

This is but an invalid, inefficient, error-prone tag soup.


PointedEars
 
P

pt36

Since checking of a database is done on the server, it seems to me that
what you want is AJAX.  Have an "onclick=foo()".  In foo you would make
the AJAX call and return a message to the browser depending upon whether
there is no match or is a match.  If this is for checking before
submitting the page, then get rid of the check button, keep the action
as the where you want the page submitted to, put a "return foo()" in the
form definition, and return either false or true from foo.

What do you mean by it doesn't work?  Does the php file not see the
value?  Does the php file see the value, but you don't get values back
to the current page?  What happens?- Nascondi testo citato

- Mostra testo citato

ok Well
i have a page that submit a form. In the page, near to the textbox
when a user insert his nik, I want that the user be alerted that the
nik inserted in the textbox is already used, so have to choose
another. I will that this happen before to submit the form.
In php after submitting the page I am able to check this, and also I
not need help for the php code for this.
I am able to make this procedure and see the alert in a new windows
popup.
I will that the alert appear in the page, near the textbox, (in a DIV)
If an Ajax procedure helps me i say thanks, please send suggestions.

When I say "not work" I mean that the link was wrote not corrected and
not work.
if you write my code you see what happen
In the first example the link open the page page_check.php
In the second example the link not open the page_page.php and the link
path is incorrect.

eg. When a user try to register to yahoo, when you write your
username, sometime you receive a warning that your username is not
available. I want to do the same.
Regards
 
T

Thomas 'PointedEars' Lahn

pt36 said:
i have a page that submit a form. In the page, near to the textbox
when a user insert his nik, I want that the user be alerted that the
nik inserted in the textbox is already used, so have to choose
another. I will that this happen before to submit the form.
In php after submitting the page I am able to check this, and also I
not need help for the php code for this.
I am able to make this procedure and see the alert in a new windows
popup.
I will that the alert appear in the page, near the textbox, (in a DIV)

Apparently you don't mean an alert message window. Note that `alert' has
a somewhat fixed meaning when dicussion client-side scripting, denoting
window.alert(). That may have caused confusion.
If an Ajax procedure helps me i say thanks, please send suggestions.

<http://developer.mozilla.org/en/docs/AJAX> is a good starting point. You
should also search the Google archives of this newsgroup, there are plenty
of XHR examples in it (many of them posted by me).

As for the form, here is a template for you to experiment with:

<form action="..." onsubmit="return checkUser(this)">
<script type="text/javascript">
function checkUser(f)
{
// use wrapper object with feature test here instead
var x = new XMLHttpRequest();

// "synchronous" request to request plain text (SJAT ;-))
x.open("GET", "/check_user?user="
+ encodeURIComponent(f.elements["username"].value), false);
x.send(null);
if (x.status == 200 && x.responseText == "1")
{
// user exists already
return false;
}
else
{
return true;
}
}
</script>

<input name="username">
<input type="submit">
When I say "not work" I mean that the link was wrote not corrected and
not work.

Your approach appears to be wrong in the first place. See also
eg. When a user try to register to yahoo, when you write your
username, sometime you receive a warning that your username is not
available. I want to do the same.

Are you sure this warning is displayed before the register form is
submitted? If yes, you can simply look at Yahoo's source code to see how it
was done client-side, and with Firebug and LiveHTTPHeaders you can see what
is requested from the server and how the HTTP response looks like.


HTH

PointedEars
 
P

pt36

ok Well
i have a page that submit a form. In the page, near to the textbox
when a user insert his nik, I want that the user be alerted that the
nik inserted in the textbox is already used, so have to choose
another. I will that this happen before to submit the form.
In php after submitting the page I am able to check this, and also I
not need help for the php code for this.
I am able to make this procedure and see the alert in a new windows
popup.
I will that the alert appear in the page, near the textbox, (in a DIV)
If an Ajax procedure helps me i say thanks, please send suggestions.

When I say "not work" I mean that the link was wrote not corrected and
not work.
if you write my code you see what happen
In the first example the link open the page page_check.php
In the second example the link not open the page_page.php and the link
path is incorrect.

eg. When a user try to register to yahoo, when you write your
username, sometime you receive a warning that your username is not
available. I want to do the same.
Regards- Nascondi testo citato

- Mostra testo citato

I Found this good tutorial and I solved
http://www.tutorialtoday.com/read_tutorial/115/
Thanks to all
 
S

SAM

pt36 a écrit :
I will that the alert appear in the page, near the textbox, (in a DIV)
If an Ajax procedure helps me i say thanks, please send suggestions.

Put the file with your form in a tag "object"
The answer will be send back in the same tag (without needing Ajax)
That works almost like an iframe

Then ... what to do with the answer is another question ;-)
 
D

Doug Gunnoe

This is but an invalid, inefficient, error-prone tag soup.

PointedEars
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann

Says you.

Anyway, sorry for the double post. I had some issues last night.

As to PointedEars comments, the answer I gave answered the question
she asked. Which I know is a rather difficult concept for you and a
few others to grasp. Not every question requires a lecture on
standards and specifications and best practice for crying out loud.

Furthermore, if I were trying to solve the problem she had, I would
have never used javascript. There is really no good reason to use it
for this problem, from what I can tell from her question.

But that's really not for me to say. She asked how to do something
using JavaScript and I gave her two workable solutions.

And don't respond to this with anything other than: "Yes Doug, you are
right and I, Thomas 'Pointed Ears' Lahn am wrong and humbly bey your
forgiveness".

And don't adjust the score either. So help me if you adjust the
score...
 
T

Thomas 'PointedEars' Lahn

Doug said:
This is but an invalid, inefficient, error-prone tag soup.
[...] -- Bjoern Hoehrmann

Says you.

And I also say to you: Learn to quote. Finally.
[...]
As to PointedEars comments, the answer I gave answered the question
she asked. Which I know is a rather difficult concept for you and a
few others to grasp.

We strive to provide the best possible answers here, not the quickest ones.


PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,054
Latest member
LucyCarper

Latest Threads

Top