473,385 Members | 1,359 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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.action="/my/action";
document.form.search="?important=1&variables=1&onl y=1"
document.form.submit();
}

This doesn't seem to work, nor does making an '.action' with an
embedded search string (document.form.action =
"/my/action?my=1&variables=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 3312
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.action="/my/action";
document.form.search="?important=1&variables=1&onl y=1"
document.form.submit();
}

This doesn't seem to work, nor does making an '.action' with an
embedded search string (document.form.action =
"/my/action?my=1&variables=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.myurl=
"http://www.whatever.com?variable=1&value=1";
document.form.submit();
}

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

and the form element was defined as:

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

Could you use this to make a call to document.form.myurl? 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.myurl=
"http://www.whatever.com?variable=1&value=1";
document.form.submit();
}

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

and the form element was defined as:

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

Could you use this to make a call to document.form.myurl? 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.location 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.myurl=
"http://www.whatever.com?variable=1&value=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.myurl.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.submit();
}
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="javascript: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.myurl? 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="return 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.location 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.submit() 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.attrib.value = x, not
document.form.attrib=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.location and document.form.action
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.location 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.submit() 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.attrib.value = x, not
document.form.attrib=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.element 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.location and document.form.action
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
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...
3
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...
3
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...
4
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...
2
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...
11
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...
6
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...
1
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...
1
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.