By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,605 Members | 2,129 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,605 IT Pros & Developers. It's quick & easy.

append textbox value to href link before submit

P: n/a
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
Jul 8 '08 #1
Share this Question
Share on Google+
10 Replies


P: n/a
pt36 wrote:
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
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?
Jul 8 '08 #2

P: n/a
On Jul 7, 9:03 pm, pt36 <key.albe...@gmail.comwrote:
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>
Jul 9 '08 #3

P: n/a
On Jul 7, 9:03 pm, pt36 <key.albe...@gmail.comwrote:
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>
Jul 9 '08 #4

P: n/a
Doug Gunnoe wrote:
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
--
realism: HTML 4.01 Strict
evangelism: XHTML 1.0 Strict
madness: XHTML 1.1 as application/xhtml+xml
-- Bjoern Hoehrmann
Jul 9 '08 #5

P: n/a
On 8 Lug, 12:49, sheldonlg <sheldonlgwrote:
pt36 wrote:
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

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
Jul 9 '08 #6

P: n/a
pt36 wrote:
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/AJAXis 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">
</form>
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
<http://jibbering.com/faq/#FAQ4_24>.
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
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
Jul 9 '08 #7

P: n/a
On 9 Lug, 10:01, pt36 <key.albe...@gmail.comwrote:
On 8 Lug, 12:49, sheldonlg <sheldonlgwrote:


pt36 wrote:
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
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- Nascondi testo citato

- Mostra testo citato
I Found this good tutorial and I solved
http://www.tutorialtoday.com/read_tutorial/115/
Thanks to all
Jul 9 '08 #8

P: n/a
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 ;-)

--
sm
Jul 9 '08 #9

P: n/a
On Jul 8, 8:49 pm, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
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...

Jul 10 '08 #10

P: n/a
Doug Gunnoe wrote:
On Jul 8, 8:49 pm, Thomas 'PointedEars' Lahn <PointedE...@web.de>
wrote:
>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
--
Anyone who slaps a 'this page is best viewed with Browser X' label on
a Web page appears to be yearning for the bad old days, before the Web,
when you had very little chance of reading a document written on another
computer, another word processor, or another network. -- Tim Berners-Lee
Jul 13 '08 #11

This discussion thread is closed

Replies have been disabled for this discussion.