473,549 Members | 2,346 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

changing 'search' part of url on submit

hey all,

Ok, a related question to my previous one on data dumpers for
postscript.

In the process of putting a form together, I'm using a lot of
placeholder variables that I really don't care about in the submitted
action. I'd therefore
like to get rid of them by doing something like:

function my_function
{
document.form.a ction="/my/action";
document.form.s earch="?importa nt=1&variables= 1&only=1"
document.form.s ubmit();
}

This doesn't seem to work, nor does making an '.action' with an
embedded search string (document.form. action =
"/my/action?my=1&var iables=1") Javascript seems to merrily ignore
these statements and simply evaluate the submit call with the html
variables.

How do you modify this value?

thanks again,

Ed

Jul 23 '05 #1
8 3334
Lee
horos said:

hey all,

Ok, a related question to my previous one on data dumpers for
postscript.

In the process of putting a form together, I'm using a lot of
placeholder variables that I really don't care about in the submitted
action.
So why are they in the form? If you want variables, use variables.
I'd therefore
like to get rid of them by doing something like:

function my_function
{
document.form.a ction="/my/action";
document.form.s earch="?importa nt=1&variables= 1&only=1"
document.form.s ubmit();
}

This doesn't seem to work, nor does making an '.action' with an
embedded search string (document.form. action =
"/my/action?my=1&var iables=1") Javascript seems to merrily ignore
these statements and simply evaluate the submit call with the html
variables.

How do you modify this value?


I don't believe a form has a search attribute. URL's do.
You can either set the search attribute of the URL, and not submit
the form, or you can submit the form and let the browser set the search
attribute.

Jul 23 '05 #2
> So why are they in the form? If you want variables, use
variables.
My point is that I want to use javascript to set the variables for a
url that I'm submitting. If there is a URL object that I could use to
do my dirty work, by all means I'd love to use it. A syntax primer
would be nice.
I don't believe a form has a search attribute. URL's do.
You can either set the search attribute of the URL, and not
submit the form, or you can submit the form and let the
browser set the search attribute.


Fair enough, but again an example would be cool. Like I said, I'm
rather new at all this. All of this would be solved if there was a
pretty datastructure printer that could show you what you could and
could not set given a javascript object.

Venkman comes close, but annoyingly it doesn't let you search the
attributes of the variables that you print out in the
'local variables' window...

Ed

Jul 23 '05 #3
horos wrote:
So why are they in the form? If you want variables, use
variables.

My point is that I want to use javascript to set the variables for a
url that I'm submitting. If there is a URL object that I could use to
do my dirty work, by all means I'd love to use it. A syntax primer
would be nice.


This is frequently done by putting a generated string in a hidden
form element that gets submitted with the form. The issue is that
if the user has JavaScript disabled, the hidden element wont be
populated with your string and you have to parse the submitted
name/value pairs anyway.

Create your string with the onsubmit event as by then the user should
have finished making selections and entering data so less event
handling for you.

[...]
--
Rob
Jul 23 '05 #4
> Create your string with the onsubmit event as by then the user
should have finished making selections and entering data so
less event handling for you.

Right, is what you are saying is that can you trigger the javascript to
fire a totally different URL than the one that is specied by a submit
call? And can onsubmit respond to a javascript submit function?

ie: say I had the following javascript:

function download_submit ()
{
document.form.m yurl=
"http://www.whatever.co m?variable=1&va lue=1";
document.form.s ubmit();
}

function on_submit()
{
return(document .form.myurl);
}

and the form element was defined as:

<form name="myform" onsubmit="javas cript:on_submit ()">
... some element using download_submit ()
...
</form>

Could you use this to make a call to document.form.m yurl? ie: the
download function would call submit, which would in turn call on_submit
to return a url to the form which would then be displayed? Right now,
my testing is saying no, but then again I could be doing something
wrong.

Ed

Jul 23 '05 #5
horos wrote:
> Create your string with the onsubmit event as by then the user

should have finished making selections and entering data so
less event handling for you.


Right, is what you are saying is that can you trigger the javascript to
fire a totally different URL than the one that is specied by a submit
call? And can onsubmit respond to a javascript submit function?

ie: say I had the following javascript:

function download_submit ()
{
document.form.m yurl=
"http://www.whatever.co m?variable=1&va lue=1";
document.form.s ubmit();
}

function on_submit()
{
return(document .form.myurl);
}

and the form element was defined as:

<form name="myform" onsubmit="javas cript:on_submit ()">
... some element using download_submit ()
...
</form>

Could you use this to make a call to document.form.m yurl? ie: the
download function would call submit, which would in turn call on_submit
to return a url to the form which would then be displayed? Right now,
my testing is saying no, but then again I could be doing something
wrong.


If you want to navigate to a page other than the one in the form's
action attribute, why are you using a form at all? Simply build the
string you want appended, create your URL, then change the
document.locati on and voila!
Jul 23 '05 #6
horos wrote:
> Create your string with the onsubmit event as by then the user
should have finished making selections and entering data so
less event handling for you.


Right, is what you are saying is that can you trigger the javascript to
fire a totally different URL than the one that is specied by a submit
call?


No, but you could if you wanted to. A form provides functionality to
send data to the server without using any JavaScript. You should
allow for the case where your script does not execute and the form is
just submitted. Presumably you are just using JavaScript to make the
submission more efficient for those users that have it available.

So the tactic is to get the form to submit the 'URL' that you want,
an example is below. When 'submit' is clicked, the onsubmit event is
fired. It gets the value from the visible field, adds it to the
hidden field (with a trivial modification), enables the hidden field,
disables the visible field, then returns 'true' so that the form
submits itself with the value of the hidden field in the 'URL'.

You can process the fields and build up whatever string you like in
the hidden field, then just let the form submit it.

I also do some trivial validation - if the text element is empty, an
alert is triggered, the function returns 'false' to the onsubmit
handler, which returns false to the form and so it doesn't submit.

If JavaScript is disabled, the form will just submit with the value
in the visible text field - the hidden field is disabled by default
so it won't be submitted. This way your server knows what it's
getting.

And can onsubmit respond to a javascript submit function?
Yes.
ie: say I had the following javascript:

function download_submit ()
{
document.form.m yurl=
"http://www.whatever.co m?variable=1&va lue=1";
This is probably not doing what you think it should. :-)

'document.form' references the form named "form". The next bit
after the dot should match an element name in the form - it is
equivalent to:

document.forms['form'].elements['myurl']

Do you have an element called 'myurl'? If not, you are creating a
'myurl' property of the form and setting its value to "http://w..."

If you want to set a property of the element, such as its value:

document.form.m yurl.value = 'some value';

Presuming that an element named 'myurl' exists in the form called
'form' and it has a value property that can be set.

A form does not have a 'url' (or 'URL') property:

<URL:http://www.w3.org/TR/html4/interact/forms.html#edef-FORM>
document.form.s ubmit();
}
Bzzzzt. You have onsubmit calling a function that itself calls
submit(), which will fire the onsubmit, which calls the function,
which calls submit()... you are in an endless loop. Have your
function return 'true' and the form will submit itself.

function on_submit()
{
return(document .form.myurl);
I guess this will return something to the onsubmit handler, which
may evaluate it to true (or something other than 'false') and submit
the form ... or not.
}

and the form element was defined as:

<form name="myform" onsubmit="javas cript:on_submit ()">
No need for the 'javascript:' pseudoprotocol. JavaScript is assumed,
unless you've used some other script type earlier (say VBscript).
... some element using download_submit ()
...
</form>

Could you use this to make a call to document.form.m yurl? ie: the
download function would call submit, which would in turn call on_submit
to return a url to the form which would then be displayed? Right now,
my testing is saying no, but then again I could be doing something
wrong.


This appears a bit muddled, have a look at the example below.

<script type="text/javascript">

function doSubmit(f){
var t = f.elements['tField'];

// Do some validation
if ( '' == t.value ){
alert('Please put something into the text field');
if (t.focus) t.focus();

// Stop form submitting if test failed
return false;
}

f.elements['hField'].value = 'horos\'s custom field'
+ f.elements['tField'].value;

// Disable visible field
f.elements['tField'].disabled = true;

// Enable hidden field
f.elements['hField'].disabled = false;

// Let form submit
return true;
}
</script>

<body>
<form action="" onsubmit="retur n doSubmit(this); ">
<input type="hidden" name="hField" disabled>
<input type="text" name="tField" value="some text">
<br>
<input type="submit" value="Submit form">
<input type="reset">
</form>


--
Rob
Jul 23 '05 #7
> If you want to navigate to a page other than the one in the form's
action attribute, why are you using a form at all? Simply build the
string you want appended, create your URL, then change the
document.locati on and voila!


thanks...

that's the answer I was looking for.

Just a few points from all this for those who search later:

1) you can't use a document.form.s ubmit() to trigger an onsubmit
tag (for some stupid reason)

2) to set any input you need to toggle the .value attribute of that
input, not the input itself (ie: document.form.a ttrib.value = x, not
document.form.a ttrib=x. You have to add a hell of a lot of frickin'
'value's ont the end of things to get stuff done imo) Of course there
seem to be some exceptions - document.locati on and document.form.a ction
being two - but this makes things even more confusing.

3) there is a command dd(), that is bundled with Venkman (the
javascript debugger) which allows for data dumping of forms and other
javascript objects.

Anyways, so far, it seems that javascript is a bit clunky for my
tastes... things don't seem to do what the user wants smoothly -- eg,
there's no reason why you *shouldn't* be able to customize a form to go
to anywhere you want with whatever search string you desire, likewise
data structure dumping *should* be built in..

Perhaps it'll get better as time goes on, but right now I feel that
I'm fighting the language to get done what I need to get done. I never
felt that way with perl, python, or C (java is another matter
though)...

Anyways, thanks much,

Ed

Jul 23 '05 #8
horos wrote:
If you want to navigate to a page other than the one in the form's
action attribute, why are you using a form at all? Simply build the
string you want appended, create your URL, then change the
document.loca tion and voila!

thanks...

that's the answer I was looking for.

Just a few points from all this for those who search later:

1) you can't use a document.form.s ubmit() to trigger an onsubmit
tag (for some stupid reason)


You can execute a form's onsubmit event two ways:

1. Call the submit buttons' click handler (supposing we named it
"submitA" in a form named "formA"):

document.forms['formA'].elements['submitA'].click();

2. Call it directly:

document.forms['formA'].onsubmit();

Note: this will not submit the form, if that is to happen, then:

if ( false != document.forms['formA'].onsubmit() ) {
document.forms['formA'].submit();
}

will do it onsubmit() returns something other than 'false'.

2) to set any input you need to toggle the .value attribute of that
input, not the input itself (ie: document.form.a ttrib.value = x, not
document.form.a ttrib=x. You have to add a hell of a lot of frickin'
'value's ont the end of things to get stuff done imo)

Of course. document.form.e lement is an element, not an attribute,
you can't 'set' it. You *can* set the element's attributes or
properties, one of which is the value. It likely also has name, id,
style and other attributes/properties that can be set. All are
specified in the HTML specification.

<URL:http://www.w3.org/TR/html4/interact/forms.html#edef-FORM>
Of course there
seem to be some exceptions - document.locati on and document.form.a ction
being two - but this makes things even more confusing.
'location' is an attribute of the 'document' object and is
supported as "level 0", that is, it is legacy from before the first
W3C specification. It is supposed to be only a getter, but it seems
to operate the same as window.location . Others here know far more
about this than I do.
'action' is a property of the form object, just like 'value' is a
property of a form element.

What you are really complaining about is not being able to
distinguish between objects, methods, properties, etc. This is
common to all 'dot notation' languages - you either have to know the
correct syntax, look it up or work it out.

A good start is the element and attribute appendices to the HTML
specification:

<URL:http://www.w3.org/TR/html4/index/elements.html>

<URL:http://www.w3.org/TR/html4/index/attributes.html >

3) there is a command dd(), that is bundled with Venkman (the
javascript debugger) which allows for data dumping of forms and other
javascript objects.

Anyways, so far, it seems that javascript is a bit clunky for my
tastes... things don't seem to do what the user wants smoothly -- eg,
there's no reason why you *shouldn't* be able to customize a form to go
to anywhere you want with whatever search string you desire,
You can.
likewise
data structure dumping *should* be built in..

Perhaps it'll get better as time goes on, but right now I feel that
I'm fighting the language to get done what I need to get done. I never
felt that way with perl, python, or C (java is another matter
though)...

Anyways, thanks much,

Ed

--
Rob
Jul 23 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
6356
by: Matt | last post by:
Hi group, Here's a problem I've been trying to solve for the past several weeks. I have the standard WebBrowser object added to a form so it can access websites, and I have it load a default page once the form is launched. I now want to automatically fill out a specific text-field found within the web-page that the WebBrowser object has...
3
4193
by: Alastair | last post by:
Hello guys, I've been building a search facility for an intranet site I'm part of developing and we've been building a search engine using Index Server. It mostly works, however there have been a few niggling problems and fixing it seems to be a case of patching errors as we find them so I'm thinking that it might be worth starting the...
3
2650
by: hazly | last post by:
I'm very new in the web technology and need advice on search engine. I want to develop a portal using PHP and MySQL on Linux. Need to know on the following features : 1. search engine that could search my portal (mySQL, PDF, Ms Word & others) 2. search engine that could search to few web sites specified by user/programmer
4
2164
by: MDW | last post by:
Posted this on another board, but evidently it was off-topic there...hope you folks will be able to provide some guidance. I've been working on a Web site for a business (my first non-personal site) and I want to help my client get the best search engine listing. Because this is my first for-profit site, I'm not sure what I need to do for...
2
1776
by: caine | last post by:
I'm doing a search application for my project. My code can prompt alert popup window when the user doesn't key in any keywords. However, if the user keys in any keywords, it juz return "Please enter keywords!" whatever it is. I had set proper looping for suitable condition checking, but it is still generate the same problem. <html> <head>...
11
4936
by: Panlflzs | last post by:
Howdy, I am working on a system where I need a basic HTML form to pass data to a cfm page. The cfm page will then query a database and return any matching data. I am using MySQL. I have my HTML page with a form element that allows a user to enter search criteria. When they click submit it sends the data in the text field to a coldfusion...
6
2628
by: jej1216 | last post by:
I am trying to put together a PHP search page in which the user can select none, one, two, or three fields to search, and then the results php will build the SQL with dynamic where caluses to reflect the fields chosen. The first page, where they select the search fields and submit: <?php $db = mysql_connect("localhost", "root",...
1
1255
by: wbrands2 | last post by:
I have a basic web form that inserts information into a ms sql database and I am trying to create a search page for it. I am running into the problem that after I insert the information into the web form page, submit it, and go to my search page the newly entered information doesn't show as part of the results. If I look in management studio I see...
1
2514
by: jsaps33 | last post by:
Hi All, I'm wondering how I would change an initial value to a blank value if nothing gets entered into the text field. I have a form with multiple fields that visitors can enter data in to get the search results they want. For example right now I have this, <input id="IDX-text_landArea" name="kw_landArea" maxlength="255" type="text"...
0
7546
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
1
7503
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7830
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6071
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5387
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5111
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
1962
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1082
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
784
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.