/    Sign up×
Community /Pin to ProfileBookmark

help wanted. need custom script

I need what I’m told is a somewhat easy script.

I need a script to insert a charachter into the beginning of a form field AFTER someone clicks the submit button.

e.g. if some one types WIDGET into an <input type=”text” field, when they hit the submit button it gets submitted as ^WIDGET

feel free to contact me with a bid.

thank you for your time

to post a comment
JavaScript

9 Comments(s)

Copy linkTweet thisAlerts:
@Khalid_AliOct 16.2003 — Code snippet below will do what you are after

<script type="text/javascript">

<!--

function Process(){

var frm = document.getElementById("form1");

var len = frm.length;

var aChar = "^";

if(frm.t1.value==""){

alert("Text field is empty");

frm.t1.focus();

return false;

}

frm.t1.value = aChar+frm.t1.value;

return true;

}

//-->

</script>

</head>

<body class="body">

<form id="form1" action="" onsubmit="return Process();">

<input type="text" name="t1"/>

<input type="submit" value="process" />

</form>

</body>
Copy linkTweet thisAlerts:
@CharlesOct 16.2003 — [font=monospace]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"

"http://www.w3.org/TR/html4/strict.dtd">

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<meta name="Content-Script-Type" content="text/javascript">

<title>Example</title>

<style type="text/css">

<!--

label {display:block; margin:1em 0em}

input {display:block}

-->

</style>

<form action="" onsubmit="this.string.value = '^' + this.string.value">

<div>

<label>String<input type="text" name="string"></label>

<button type="Submit">Submit</button>

</div>

</form>[/font]
Copy linkTweet thisAlerts:
@letsauthorOct 16.2003 — Mayby I"m close....... here's what I did

I added the following above the <head>

<script type="text/javascript">

<!--

function Process(){

var frm = document.getElementById("form1");

var len = frm.length;

var aChar = "^";

if(frm.t1.value==""){

alert("Text field is empty");

frm.t1.focus();

return false;

}

frm.t1.value = aChar+frm.t1.value;

return true;

}

//-->

</script>

Then I added [onsubmit="return Process();"] like so;

this was the original;

<input TYPE=TEXT value=" " name="custom5" size="5" maxlength="10"">


And I changed it to this;

<input TYPE=TEXT value=" " name="custom5" size="5" maxlength="10" onsubmit="return Process();">


I know, I didn't do something right....... if it helps, thre page I'm trying to add this to is;

http://www.rhtubs.com/store/insulate-test.htm

I'm trying to add this to ALL the text fields on the page.
Copy linkTweet thisAlerts:
@CharlesOct 16.2003 — [font=monospace]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"

"http://www.w3.org/TR/html4/strict.dtd">

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<meta name="Content-Script-Type" content="text/javascript">

<title>Example</title>

<style type="text/css">

<!--

label {display:block; margin:1em 0em}

input {display:block}

-->

</style>

<form action="" onsubmit="for (var i=0; i<this.elements.length; i++) {if (this.elements[i].type == 'text') this.elements[i].value = '^' + this.elements[i].value}">

<div>

<label>String 1<input type="text"></label>

<label>String 2<input type="text"></label>

<label>String 3<input type="text"></label>

<label>String 4<input type="text"></label>

<button type="Submit">Submit</button>

</div>

</form>[/font]
Copy linkTweet thisAlerts:
@letsauthorOct 17.2003 — hmmm, Well I thank you Charles for your post and the trouble it took you. Unfortunatly, I don't have a clue what to do with it or how to implement it into my form.

Thank you though
Copy linkTweet thisAlerts:
@stephenoOct 17.2003 — The onsubmit event should be added to the form tag not the input tags. Also you will need to add the frm.t1.value = aChar+frm.t1.value; line of code for each input field in your form you want to add the ^ to. When you do replace the t1 with the name of each input tag you are adding the character to.
Copy linkTweet thisAlerts:
@letsauthorOct 17.2003 — I just realized, my original post was missing something.....it should have read, "help wanted, WILL pay!"

I'm getting more and more lost on this.
Copy linkTweet thisAlerts:
@CharlesOct 17.2003 — [i]Originally posted by lets [/i]

[B]hmmm, Well I thank you Charles for your post and the trouble it took you. Unfortunatly, I don't have a clue what to do with it or how to implement it into my form.



Thank you though [/B]
[/QUOTE]
[font=monospace]<form action="" onsubmit="for (var i=0; i<this.elements.length; i++) {if (this.elements[i].type == 'text') this.elements[i].value = '^' + this.elements[i].value}">[/font][font=georgia]



Between the time that the submit button is hit and the form is actually submitted that script will step through all of the form elements. If the element is a text box then its value will be prepended with a "^". And unless I've misunderstood, that's what you are after.[/font]
Copy linkTweet thisAlerts:
@letsauthorOct 17.2003 — Sir Charles, thank you for your patience and additional explanation...... IT WORKS!

I can't thank you enough..... Let me know if there's a way I repay you for your kindness.

Again, thank you so SO much
×

Success!

Help @lets spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...