473,386 Members | 1,621 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,386 software developers and data experts.

Call documentGetElementById without event

KeredDrahcir
426 256MB
I need to change the background of an input box depending on if a radio button on a form has been selected or not.
I'm trying to do it using a documentGetElementById which is called when the php checks the radio buttons. There is no event to call the documentGetElementById. Can I still call it without an event?
Jul 20 '10 #1

✓ answered by KeredDrahcir

Define the boxs you want to change will their ID name. After the boxes use something like this:
Expand|Select|Wrap|Line Numbers
  1. <?
  2.   if ((!strcmp($_POST['preferred'],"email")) || (!($_POST['preferred'])))
  3.   {
  4.     echo "<script type="text/javascript">
  5.       document.getElementById('email').style.backgroundColor='#d7ebff'; document.getElementById('phone').style.backgroundColor='#ffffff';
  6.     </script>";
  7.   }
  8.   else
  9.   {
  10.     echo "<script type="text/javascript">
  11.       document.getElementById('phone').style.backgroundColor='#d7ebff'; document.getElementById('email').style.backgroundColor='#ffffff';
  12.     </script>";
  13.   }
  14. ?>
  15.  

7 2024
Dormilich
8,658 Expert Mod 8TB
a) the call is document.getElementById() (JavaScript is case sensitive)
b) if you do processing with PHP, it’s too late for JavaScript.
Jul 20 '10 #2
KeredDrahcir
426 256MB
Is there some way I can change the style of something using php similar to the way Javascript uses;
documentGetElementById('id').style.backgroundColor ='#df8ff9';
Jul 20 '10 #3
Dormilich
8,658 Expert Mod 8TB
no. PHP and Javascript have a totally different way of "interacting" with HTML.
Jul 20 '10 #4
KeredDrahcir
426 256MB
All I want to do as the page load is to check a POST value and if it is unset or one value set the background colour of an input box, and if it is another value set the background colour of a different box.
Surely there must be a simple way of doing this.
Jul 21 '10 #5
Dormilich
8,658 Expert Mod 8TB
if you want to check a POST value, you need a server-side language like PHP or ASP. then everything else is just a modification of the source code.
Jul 21 '10 #6
KeredDrahcir
426 256MB
Define the boxs you want to change will their ID name. After the boxes use something like this:
Expand|Select|Wrap|Line Numbers
  1. <?
  2.   if ((!strcmp($_POST['preferred'],"email")) || (!($_POST['preferred'])))
  3.   {
  4.     echo "<script type="text/javascript">
  5.       document.getElementById('email').style.backgroundColor='#d7ebff'; document.getElementById('phone').style.backgroundColor='#ffffff';
  6.     </script>";
  7.   }
  8.   else
  9.   {
  10.     echo "<script type="text/javascript">
  11.       document.getElementById('phone').style.backgroundColor='#d7ebff'; document.getElementById('email').style.backgroundColor='#ffffff';
  12.     </script>";
  13.   }
  14. ?>
  15.  
Jul 21 '10 #7
Dormilich
8,658 Expert Mod 8TB
I wouldn’t use JavaScript, if I could edit the CSS right away.
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $color1 = '#d7ebff';
  3. $color2 = '#fff';
  4. if ((!strcmp($_POST['preferred'],"email")) || (!($_POST['preferred'])))
  5. {
  6. $color1 = '#fff';
  7. $color2 = '#d7ebff';
  8. }
  9. ?>
  10.  
  11. #email {
  12.     background-color: <?= $color1; ?>;
  13. }
  14.  
  15. #phone {
  16.     background-color: <?= $color2; ?>;
  17. }
Jul 21 '10 #8

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

Similar topics

2
by: John S | last post by:
Is it possible to call the click event of a control from another method or class?
3
by: Alexander | last post by:
I have a dialog that loads a file from a web server, this is done in an own thread. On finish or failure the thread is supposed to raise an event notifying the dialog. If the WebRequest now raises...
20
by: anthonymelillo | last post by:
Is there a way to call a button click event from somewhere else ? I have a text box where I would like to call a button click event when a user presses enter in the text box. Can I do this ?...
3
by: Bryan | last post by:
I pass my form's collection of controls to a public sub in a module that loops through and checks for any ErrorProvider text. The sub returns all the ErrorProvider strings that were found for...
3
by: Sidanalism | last post by:
I miss the old way when asynchronous calls are driven my window messages. Yes a thread pool might greatly improve application performance but there are time I don't want my event to be fire in a...
6
by: pronerd | last post by:
Hi, I am trying to dynamically set an event handler across frames. I have no problems setting properties across frames doing something like parent.ToolMenuFrame.location.href =...
2
by: GauravGupta | last post by:
i am displaying a table in page load whose data is fetched from database . it also check what data is to be displayed from data base by a session variable. and i have few button which change the...
0
by: progman417 | last post by:
Hello, I've got a Web User Control containing a gridview with a "select record" button on each row. When the user clicks the button I want to call an event handler in the main page. My...
3
by: phpmel | last post by:
hi guys, I have 2 gridviews, one inside a modal popup(gvSuppliers) and one on the page(gvFirms). The header row of the gvFirms has 4 text boxes. I can find those controls easily inside the...
1
by: gracepaul | last post by:
hi all, I want to call the Mouse_Click event from the previous form f1 in the next form f2. how can do that? when i close the form f2 and then raise the mouse_click event in form f1 at that...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.