473,785 Members | 2,414 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Javascript invalid character issue

4 New Member
Hello,

Sorta new with JavaScript... so don't kill me with jargon.

I am trying to make a script that will only allow text to be inputted into a textarea that is from a drop down menu. My problem is the textarea/textbox id is pre-set and unchangeable by the shopping cart system I use. (*Changing it will make it un-upgradeable in the future)

Here is what I have so far:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>Dropdown to Textbox</title>
  4. <script type="text/javascript">
  5. function setName(child)
  6. {
  7.  
  8.      document.all.attrib-1-0.value = child.options[child.selectedIndex].text;
  9.  
  10. }
  11. </script>
  12. </head>
  13. <body>
  14.  
  15. <select name="name" onchange="setName(this)">
  16. <option value="001">AJ</option>
  17. <option value="002">Andrew</option>
  18. <option value="003">Andy</option>
  19. </select>
  20.  
  21. <input type="text" name="id[txt_1]" size="32" maxlength="32" value="" id="attrib-1-0" />
  22.  
  23. </body>
  24. </html>
If you replace "attrib-1-0.value" with "foo" in both the script and the text field you will see a working version of the code. It's the invalid characters that mess it up. Now, I have tried to comment the invalid characters out with "/" but it didn't work.

Any suggestions?
Jul 7 '08 #1
6 2865
acoder
16,027 Recognized Expert Moderator MVP
Firstly, change document.all to document.getEle mentById. For the ID, use a string:
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("attrib-1-0")...
Jul 7 '08 #2
jasmel
4 New Member
ok...

That suggestion helped me with another issue I was having: (using the getElementById)

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. function notEmpty(){
  3.     var myTextField = document.getElementById('attrib-1-0');
  4.     if(myTextField.value != "")
  5.         alert("You entered: " + myTextField.value)
  6.     else
  7.         alert("Please select child's name from dropdown menu")        
  8. }
  9. </script>
however, I still can't get the selected option to go into the textbox using the getElementById

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>Dropdown Option To Textbox</title>
  4.  
  5. <script type="text/javascript">
  6. function notEmpty(){
  7.     var myTextField = document.getElementById('attrib-1-0');
  8.     if(myTextField.value != "")
  9.         alert("You entered: " + myTextField.value)
  10.     else
  11.         alert("Please select child's name from dropdown menu")        
  12. }
  13. </script>
  14.  
  15. <script type="text/javascript">
  16. function setName(child)
  17. {
  18.  
  19.      document.getElementById.("attrib-1-0") = child.options[child.selectedIndex].text;
  20.  
  21. }
  22. </script>
  23. </head>
  24. <body>
  25.  
  26. <select name="name" onchange="setName(this)">
  27. <option value="001">AJ</option>
  28. <option value="002">Andrew</option>
  29. <option value="003">Andy</option>
  30. </select>
  31.  
  32. <input type="text" name="id[txt_1]" size="32" maxlength="32" value="" id="attrib-1-0" />
  33.  
  34. <input type='button' onclick='notEmpty()' value='Submit' />
  35.  
  36. </body>
  37. </html>
Jul 7 '08 #3
acoder
16,027 Recognized Expert Moderator MVP
You're not using it correctly. Look how you used it in the notEmpty() function.
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("attrib-1-0").value = child.options[child.selectedIndex].text;
Jul 7 '08 #4
jasmel
4 New Member
I also just remembered to put a readonly on the text box as well. Hopefully this will stop folks from ordering the wrong child's names.

Originally I had a drop down menu of child's names then the customer had to input the data into the correct text box. It became a nightmare..

Thanks again!
Jul 7 '08 #5
jasmel
4 New Member
I used your readOnly script found here:

http://www.w3schools.c om/htmldom/prop_text_reado nly.asp

You're the best!
Jul 8 '08 #6
acoder
16,027 Recognized Expert Moderator MVP
If you needed the value instead of the names, you could replace ".text" with ".value" or even document.getEle mentById("attri b-1-0").value.

Just a point to bear in mind: client-side error checking is not enough, it's only a convenience. Someone could modify or turn off JavaScript. The real checking should take place on the server-side. You may already have done, but thought I'd just make sure.

Oh, and I'm glad to see that you're happy with the service! ;)
Jul 8 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

25
3747
by: delerious | last post by:
I see some code examples like this: <DIV onmouseover="this.style.background='blue'"> and other code examples like this: <DIV onmouseover="javascript:this.style.background='blue'"> Which way is more proper? Or are both ways perfectly fine? Are there any specifications that discuss when "javascript:" should be put in front of code?
8
1724
by: Sue | last post by:
In this code why is it that when I press the SUBMIT button the focus only goes back to the Numeric field. What do I need to do to correct this problem? Sue <html>
5
2693
by: Sue | last post by:
After finishing up my first quarter JavaScript on 12/12/03, I decided to improve character checking on my project. In my project I only had to do very basic validation. Therefore, I only had one function to verify the name fields, age, email and gender. My question is: if I create a function for each field like the code below, what would be the best way to organize the functions and call them? Would I need one main function and place...
9
8156
by: Safalra | last post by:
The idea here is relatively simple: a java program (I'm using JDK1.4 if that makes a difference) that loads an HTML file, removes invalid characters (or replaces them in the case of common ones like Microsoft's 'smartquotes'), and outputs the file. The problem is these files will be on disk, so the program won't have the character encoding information from the server. Questions:
4
7251
by: Roger Redford | last post by:
Dear Experts, I'm attempting to marry a system to an Oracle 817 datbase. Oracle is my specialty, the back end mainly, so I don't know much about java or javascript. The system uses javascript to make ODBC calls to the db. The particular system I'm working with, will not work with an Oracle stored procedure I'm told. However, it
12
9645
by: Jeff S | last post by:
In a VB.NET code behind module, I build a string for a link that points to a JavaScript function. The two lines of code below show what is relevant. PopupLink = "javascript:PopUpWindow(" & Chr(34) & PopUpWindowTitle & Chr(34) & ", " & Chr(34) & CurrentEventDetails & ")" strTemp += "<BR><A HREF='#' onClick='" & PopupLink & "'>" & EventName & "</A><BR>" The problem I have is that when the string variables or contain a string with an...
10
4709
by: Shadow Lynx | last post by:
That subject packs a whallop, so let me explain in better detail what's happening and how it relates to ASPX pages... In a nutshell, if the first <script /on a page is of type "text/vbscript", you cannot use inline JavaScript statements that call setTimeout with functions that start with a double-underscore. This is very relavant to ASPX (ASP Dot Net) pages because it means that AutoPostBacks will fail since they generally call the...
3
3961
by: Wayne Deleersnyder | last post by:
Hi All, I'm trying to create a function that will cause a pop-up alert to appear if dates which were chosen from a drop-down list were invalid on a page. There's 4 dates, so there's the possibility of 4 errors at once. I'd like to pop-up all the errors at once, so the user can correct all the errors at once. My issue is format. I'd like a message something like... ERROR: Acquired Date Invalid - only 28 days in February for year
9
4414
by: Steve | last post by:
Hi; I've being going through some legacy code on an old JSP site I have been patching. I noticed that when I save the JSP down to my PC as an HTML file I get this javascript error in IE 6 ( not in the latest Firefox ): "invalid character" The problem traces back to this line of code:
0
10157
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10096
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9956
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8982
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 launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7504
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6742
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4055
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
2
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2887
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.