LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Simple HTML form (https://www.linuxquestions.org/questions/programming-9/simple-html-form-545957/)

SimonT 04-14-2007 03:08 AM

Simple HTML form
 
This has to be easy to do but for the life of me I can't work out how to do it,

Ok in my html form that posts to a page I have one field that I need help with and it looks like this

Code:

Enter your name <INPUT NAME="Username" value="">
When the form is submitted the value for Username has to be formated like "string:JOHN" where John would have been the name the user entered

I want to try and hide the part "string:" and not set that as a value but when the user submits the form I want that to be prefixed to the start of that value

At the moment the form looks like this

Code:

Enter your name do not remove the word string <INPUT NAME="Username" value="string:">
I want to some how hide that extra value from the user but when the form is submited to add it.

Here is the flow

Code:

Enter your name <INPUT NAME="Uname" value="">

UserName = string: & Uname

submit form


Hope some one follows that.

acid_kewpie 04-14-2007 03:30 AM

seems like it's the wrong place to do this, but it's possible. you could try to use the on_submit() function in javascript to modify the data before the submit process completes.

TefoZi 04-14-2007 05:47 AM

You should use javascript:

<html>
<script>
<!--
function process_submit()
{
document.myform.Username.value = "string:" + document.myform.Username.value;
document.myform.submit();
}
//-->
</script>

<form name="myform" action="1.htm" method="get" onsubmit="process_submit();">
<input type="text" name="Username" value="">
<input type="submit" name="submit" value="Submit">
</form>
</html>


<!-- OR -->

<html>
<script>
<!--
function process_submit()
{
document.myform.Username.value = "string:" + document.myform.Name.value;
document.myform.submit();
}
//-->
</script>

<form name="myform" action="1.htm" method="get" onsubmit="process_submit();">
<input type="text" name="Name" value="">
<input type="hidden" name="Username" value="">
<input type="submit" name="submit" value="Submit">
</form>
</html>

theNbomr 04-14-2007 11:23 AM

Just make the 'string:' component part of a hidden field. Use your CGI script that handles the form to concatenate the two field values.
--- rod.

acid_kewpie 04-14-2007 11:50 AM

but why would you even bother? if it's always just going to read "string:" then you'd just manually add it in the stndard code.. no point submitting it back to yourself is there? that's what i would've suggested already, but there was the insistence on a single parameter in that format already...

theNbomr 04-14-2007 12:57 PM

I assumed that 'string:' was just and example or placeholder for some string which may have almost any content and would probably vary in composition for any particular instance of the form.
It really sounds like the original poster is trying to create some functionality traditionally accomplished using cookies and/or hidden fields. Perhaps SimonT could explain something about how he intends to use what he wants.
--- rod.


All times are GMT -5. The time now is 11:09 PM.