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

PHP and the Document Object Model

nathj
938 Expert 512MB
Hi,

I'm currently working on a project that is making use of the DOM. This is great way to save time and code and generally make life easier. However, I have an issue that cannot seem to overcome.

I have a PHP page that deinfes a form in a disabled state. Then when the user clicks edit the controls are enabled. This is done with a call to a JS function that takes the ID of the form. Then using the elements array the disable state of each element is flipped to be what it is currently not - the value of the attirbute is inverted. This works fine. No problems there.

The trouble comes when I only want certain elements of the form to be enabled depending on the user access rights. My plan was to add an attribute to each form element and then check the value of this in the javascript as I could set that in the php depending on the access rights.

This leads to my question. How do I add a new attribute to the input elements in PHP so that they are available in the DOM?

My alternative is to pass a comma seprated list of input ID's to the JS function convert that to an array and then set the disabled status as I loop through the array. This would enable me to have different things sent over but it is not exactly future proof.

Many thanks
nathj
Dec 6 '07 #1
2 1382
pbmods
5,821 Expert 4TB
Heya, Nathj.

If you're working with a static form, it probably makes the most sense to simply give each element an ID, then create a JavaScript array of 'permitted' IDs.

If you're working with a dynamic form, you might want to consider using AJAX or else to use pure JavaScript to build the entire form and have PHP generate that JavaScript.
Dec 23 '07 #2
nathj
938 Expert 512MB
Heya, Nathj.

If you're working with a static form, it probably makes the most sense to simply give each element an ID, then create a JavaScript array of 'permitted' IDs.

If you're working with a dynamic form, you might want to consider using AJAX or else to use pure JavaScript to build the entire form and have PHP generate that JavaScript.
Hi pbmods,

The static form with the array of permitted Id's was pretty much what I went for in the end.

Thanks for the reply though, it's nice to know I'm not the only one that came up with this solution.

Cheers
nathj
Dec 24 '07 #3

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

Similar topics

13
by: Stumped and Confused | last post by:
Hello, I really, really, need some help here - I've spent hours trying to find a solution. In a nutshell, I'm trying to have a user input a value in form's textfield. The value should then be...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
6
by: Robert W. | last post by:
I'm building my first major C# program and am try to use best practices everywhere. So I've implemented the "Document/View Model" whereby: - There's a Windows Form, which we'll call "formView" -...
4
by: Joergen Bech | last post by:
Whenever no controls are selected in the VS.Net 2003 webforms designer, the Properties box defaults to "DOCUMENT", which allows me to set properties such as bgColor, bgProperties, bottomMargin,...
20
by: weston | last post by:
I've got a piece of code where, for all the world, it looks like this fails in IE 6: hometab = document.getElementById('hometab'); but this succeeds: hometabemt =...
8
by: '69 Camaro | last post by:
Perhaps I'm Googling for the wrong terms. Does anyone have links to examples of the syntax necessary to read the HTML on another Web page when that HTML is produced from JavaScript using the...
0
by: Jarod_24 | last post by:
I've tried the WebBrowser in the System.Windows.Forms namespace, but it dosen't work when you instanciate an object from a class. It needs a Form to live in to work. My application allready has...
9
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - What is the document object model? ----------------------------------------------------------------------- ...
1
by: TEK | last post by:
Hello I'm wondering if anyone have some good ideas/solution to a problem I'm working on. Target: Give the user a "MS World" like document UI to work with when editing data stored in a object...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.