JavaScript - Can I Change Set Characters Of An Input String?
I have a problem thats above my head, im new to javascript.
I want to be able to control the first three characters of an input string on a login form. If a user types GP15555 or JP15555 I want it to change to GPL5555 or JPL5555 respectively changing the "1" to an "L" on the prefix is this at all possible? any point in the right direction would be great. heres my code Code: </script> <script language="JavaScript" type="text/javascript"> //<![CDATA[ function Login(form) { var password = form.password.value; var pin = form.pin.value; var product = form.product.value; if (password) { var htsite = product + "/" + password + "/" + pin + "/index.html"; window.location = htsite; } else { alert("Please enter your password and pin."); } } // End --> //]]> </script> /thanks gp Similar TutorialsHi, So I've got an array called questions_raw Code: questions raw = [ ["<Q1> Question", "choice1","choice2", "choice3"], ["<Q2> Question", "choice1","choice2", "choice3"], ... ] And I want to list all of the questions, but not the choices/answers. So far, I've managed to list just the questions, but because another function randomly sorts them, I need to sort them back into numerical order for a separate function (displaying the questions) I use characters (>,^) at the front to separate them into different answer types (just to explain the code) I try this to cut each string down so that they can be sorted numerically/alphebetically - Code: function linearlist() { var list = []; var tempStr = ""; for (var l = 0; l < 145; l++) { tempStr = questions_raw[l][0]; list[l] = tempStr; } if (list.charAt(0)== " " ) list = list.substring(3) ; if (list.charAt(0)== ">" ) list = list.substring(3) ; if (list.charAt(0)== "^" ) list = list.substring(3) ; var sorted = list.sort(); document.Qtext2form.Qtext2.value = sorted.join("\n"); } But it doesn't like it - because "it has no method charAt" Any idea what i'm missing? Is it just that you have to put the [l] in every time you call a variable? Cheers Can some one help me, I want to replace the characters from a string and I have tried with this script: Code: var v5=form.description.value.replace(/#/, "%23"); But it only changes the first character from the string. Turning #### into %23### but I want them all transformed. How can to obtain length of string variable, for example if I have: var msg = 'hello world!'; Does it exist a method to count string characters? Here is the code i am trying. Code: var str="اسدف"; patt=/[\u0600-\u06FF\u0750-\u077F]/; result=patt.test(str); document.write("<br />Returned value: " + result); </script> This should return true, as the string in the str variable is indeed Arabic character. But it returns false. Need some help here on this.. Thanks in Advance I need to declare a variable (astString) and initialise it with a string of asterisks. astString needs to be the same length as another variable (otherString). otherString changes it value regularly so I think I need to use the .length property in some way but I can't see how! This should be simple but it's eluding me completely. My java skill are rudimentary at best. I have an email which has some values attached to a link in the email that get passed to an online form on a website when clicked. Problem is the value is a price and the string includes a "$" which I need to remove. I've read through many examples and everyone seems to have an opinion (surprise). One suggests something like this: Code: text2.value=text1.value.replace(/\$/g,""); While someone else says its better to remove what you don't want. I am also scratching my head over should I place the value into a hidden field, scrub it then copy that into the proper field? and I imagine the best way would be to run it with an "onload" command instead or a event handler like a keystroke since the field is not typed? Roundtable discussion would be appreciated to help me solve this simple problem and help expand my knowledge of java... thanks. I am making a function where I need to know whether the input is a variable with a string value var foo = "bar"; Function(foo) or if it is a string, wherein it would be the name of an object object = { ThingsInside: function(){code} } Function('object') Code: function Function (object){ if(object is a string){ do this } else if (object is a variable with a string value){ do this } else{ do something else } Because they would be both passed by value, I'm not sure how or if there is a way to tell as they would both just appear as string inputs, right? I'm trying to determine whether a word exists in the URL and if so, change the CSS of a div. I know how to do each task individually, but combining the two is giving me trouble. So far I have: Code: function checkSent(divname) { if(document.URL.indexOf("sent") >= 0) *document.getElementById(success).style.display = 'block'; } var sentornot = checkSent(); // If the URL contains the word, sent, then change the display of the element "success" to block I can successfully determine whether the string exists in the URL by adding an alert, but the Javascript to change the CSS doesn't work. The CSS for the div element "success" is as follows: Code: #success { display: none; } Any help is appreciated! Thanks! Edit: If needed, this is the code I used to test whether the "check URL" portion works: Code: function checkSent(divname) { if(document.URL.indexOf("sent") >= 0) { alert("found"); document.getElementById("success").style.display = 'block'; //this line doesn't work :( } else{ alert("not found"); } } Utilising "Search" what resides at: http://www.codingforums.com/showthread.php?t=6441 appears to be closest to my problem but does not solve it. I want to use HTML Input text boxes for processing within nested functions and with the results output back to the HTML table. The code contains the HTML and Javascript. As the code stands data is reported back to the HTML table because the wanted functions have been commented out. Within the code is a note regarding the above. If I try to engage the functions add() or take() I have "NaN" returned. I have attempted to use x=Number(yy), x=parseInt(yy), but to no avail. [code]<html > <head> </head> <body> <form id="myself"> <table border="1" bgcolor="lightblue"> <tr height="25px"> <td id="ad" width="25px"></td> <td id="sb" width="25px"></td> </tr> <tr height="25px"> <td><input id="lt" type="text" value="" onChange="calc();" style="width:20px"></td> <td><input id="rt" type="text" value="" onChange="calc();" style="width:20px"></td> </tr> </table> </form> <script language="javascript"> var mm; var nn; var tot; var subt; function calc(){ var n1=document.getElementById("lt").value; var n2=document.getElementById("rt").value; var nn; var mm; nn=Number(n1); mm=Number(n2); tot=mm+nn; // comment these lines out and ad.innerHTML=tot; // activate the functions subt=Math.abs(nn-mm); // sb.innerHTML=subt; // mm and nn need to passed to the functions //add(); //take(); } function add(){ tot=mm+nn; ad.innerHTML=tot; } function take(){ subt=Math.abs(nn-mm); sb.innerHTML=subt; } </script> </body> </html> [icode] Hi there, I'm working on a site: ocmd.co.nr And it features a lot of handy little web gadgets and apps for users. I was interested in creating a page, where two iframes are shown side-by-side both with the width of 50% and the height of 100%, with adressbars on top of each of them. So, essentially, what I need is just a code that allows the user to edit the iframe's src and get it to a different site. Still need assistance, thanks Okay, so here's an example code of what I'm needing: Code: <html> <head> <title></title> <style type="text/css"> #greenrow { background-color:#090; } #redrow { background-color:#F00; } </style> <script type="text/javascript"> if (calculate.level.value >= calculate.getElementById('shrimp').value){ class = greenrow; } else { class = redrow; } </script> </head> <body> <form name="calculate"> <table> <tr> <td><label> Level<input name="level" type="text" size="5" /></label> </td> </tr> <tr id="shrimp"> <td>Shrimp</td> <td align="center"><label> <input type="text" name="shrimp" /> </label></td> <td colspan="3" align="left">10</td> </tr> </table> </form> </body> </html> Okay so what I want to be done is to get information from the input text area "level" and IF "level" is >= 10...for this one certain row, I want it to get the class #greenrow. Else, class = #redrow. Thanks I'm trying to change a row of input fields to have the value(s) of a table row. When I click a button called Next, I want to pull in the value(s) that are already on the display. If I click Next again, I want to pull in the next row's values or if I click the button called Previous I want to get the prior lines values. Can someone please help or push me in the right direction? Thanks. Code: <script type="text/javascript"> function copyLine() { document.getElementById("pitem").value=document.getElementById("p1item").value; document.getElementById("ploc").value=document.getElementById("p1loc").value; document.getElementById("plot").value=document.getElementById("p1lot").value; document.getElementById("pqty").value=document.getElementById("p1qty").value; } </script> <table> <tr> <td><input type="text" name="item" id="pitem" size="15" value=""></td> <td><input type="text" name="loc" id="ploc" size="7" value=""></td> <td><input type="text" name="lot" id="plot" size="7" value=""></td> <td><input type="text" name="qty" id="pqty" size="10" value=""></td> </tr> <tr> <td><input type="button" value="Next" onclick="copyLine()"> <input type="button" value="Previous" /></td> </tr> <tr> <td id="p1item">Item 1</td> <td id="p1loc">Location 1</td> <td id="p1lot">Lot 1</td> <td id="p1qty">100</td> </tr> <tr> <td id="p2item">Item 2</td> <td id="p2loc">Location 2</td> <td id="p2lot">Lot 2</td> <td id="p2qty">200</td> </tr> <tr> <td id="p3item">Item 3</td> <td id="p3loc">Location 3</td> <td id="p3lot">Lot 3</td> <td id="p3qty">300</td> </tr> </table> hi i wants to change one input to texarea when i select one from radio, plz any suggestion how i would do that? my code PHP Code: <input type="text" name="other" value="this need to become textarea" /> <input type="radio" name="inputtext" />Text <input type="radio" name="inputtext" />Textarea so when i click inputtext radio name"other" will become a textrea rather then input type text. thanks for any help. Hi, I am trying to write some code that will test if a user enters a non-numeric character in an input text field, and if so, replaces it with a '0' Code: <script type="text/javascript"> function IsNumVal (){ for (J=1; J<=3; J++){ if (isNaN(Number(document.getElementById('Intext' + J).value))){ document.getElementById('Intext' + J).value = 0; } } } </script> <Body> <table border="1" cellspacing="1" id = "Numbers"> <tr id="RowNum1"> <td ><input type="text" size = "5" name="Intext1" id="Intext1" value = "3" onkeyup="IsNumVal()" /></td> </tr> <tr id="RowNum2"> <td><input type="text" size = "5" name="Intext2" id="Intext2" value = "9" onkeyup="IsNumVal()" /></td> </tr> <tr id="RowNum3"> <td><input type="text" size = "5" name="Intext3" id="Intext3" value = "18" onkeyup="IsNumVal()" /></td> </tr> </table> </Body> document.getElementById('Intext' + J).value = 0; doesn't work document.Schedule.'Intext' + J.value = 0; doesn't work document.Schedule.Intext2.value = 0; works, but I need to test each text field while looping, so I can't "hard code" the ID. Suggestions? I need to change one letter in a text string, but near as I can figure out, I can't just do this: Code: TextString[8] = "X"; Is that possible, or do I have to break the string and rebuild it into a second string? How do I change a text input's background when the user hits "Enter" or Key #13. The text-input field currently light's up to blue when hovered over, then it turns green when it is focused on, and now I want it to turn pink when you submit it. (This can be seen at http://ocmd.co.nr/ap) ------------------ Also, if anyone knows how I can redirect the user depending on there input, that'd be great. Regularly, it just runs a Google Search, but if I could get it so that when someone typed in, "chat room 1" for example, it'd open up a link or a new window w/ that. I'm trying to use an onclick function in a radio button to change the value of a hidden input in another form. What I want to happen is, when the user changes the value of the radio button (0 or 1), the value of the input named 'repeat' is set to 0 or 1 accordingly. The goal being that when I submit the form with input name='repeat' it will send the number indicated by the radio button. (Due to the structure of my page the radio button and the hidden input need to be two separate forms, but I don't think that should be a problem.) The code below isn't working -- the alert("changerepeat called") never even appears. It seems like the problem is that the onclick isn't even activating at all. Any ideas? Code: <script type="text/javascript"> function changerepeat(theval) { alert("changerepeat called"); document.forms[0].elements[0].value = theval; } function tellme() { alert("repeat = "+document.forms[0].elements[0].value); } </script> <form> <input type='hidden' name='repeat' value=''> <input type='button' value='tellme' onclick='tellme()'> </form> <form> <input type='radio' name='changerepeat' onclick='changerepeat(\'0\')'> 0 <input type='radio' name='changerepeat' onclick='changerepeat(\'1\')'> 1 </form> Thanks very much for reading! Hello, I am trying to change the value of #name and #category inputs based on the value of select. A friend gave me the code below, but I can't get it to work. Thanks so much for your help Code: <script type="text/javascript"> $('#Gift_Type').change(function(){ if ($(this).val() == 'Monthly'){ $('#name').val('Partnership') $('#category').val('Partnership') } else { $('#name').val('Donation') $('#category').val('Donations') } }) </script> Code: <SELECT NAME="sub_frequency" ID="Gift_Type" onchange="OnSelectionChanged (this)"> <OPTION VALUE="1m">Monthly</OPTION> <OPTION VALUE="">One Time</OPTION> </SELECT> Code: <input type="text" id="name" name="name" value="Partnership" /> <input type="text" id="category" name="category" value="Partnership" /> |