Solved

Disable button on php code

Posted on 2011-02-23
13
718 Views
Last Modified: 2012-05-11
Hi,
I have a button called ''btn_finalizar'' this button is disable=false, so, what I want is to after the php code, the button ''btn_finalizar'' get disabled=true. After this if statement: if ($res >= 2 && $form->submitter >= 0 ) {

$username = $_POST['curso_boxmax'];
	if ($username == "1er Ciclo") {
		if ($res >= 2 && $form->submitter >= 0 ) {
		$form->page = 2;
		}
			if ($res >= 1 && $form->submitter >= 0 ) {
			$form->error = "Usted ya ha completado la evaluación de los docentes del 1er Ciclo, usted no podrá llenar más!!!";
	?>
			<script language="javascript">
              		var btn_finalizar = document.getElementsByName('btn_finalizar')[0];   
		   	if (btn_finalizar) btn_finalizar.disabled = true;
			</script>
	<?php
}

}

Open in new window

I do not know how to disable the button in php code, the above code does not work for me.
Thanks.
0
Comment
Question by:plus_ec
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 5
13 Comments
 
LVL 40

Expert Comment

by:gurvinder372
ID: 34962625
just this would do

<body>
<input type="text" id="text1" disabled="true"/>
</body>


0
 
LVL 1

Author Comment

by:plus_ec
ID: 34962710
sorry, but, I do not understand, could you please be more detailed?
Or I don't know if I misunderstand my question?
Thanks for reply.
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 34962731
i am trying to say that you dont need javascript to disable the textbox, if the textbox has to be disabled at the page load event itself
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:plus_ec
ID: 34962902
Thanks,
But in my question I said that is a button, not a texbox.

The whole code is this:
$form->data['user_id'] = &JFactory::getUser()->id;
$db_name =  $form->formXMLStruct['database']['name'];

$query = "select count(id) from $db_name where user_id={$form->data['user_id']}";
$database = &JFactory::getDBO();
$database->setQuery($query);
$res = $database->loadResult();
if ($res == null) die($query);

$username = $_POST['curso_boxmax'];
	if ($username == "1er Ciclo") {
		if ($res >= 2 && $form->submitter >= 0 ) {
		$form->page = 2;
		}
			if ($res >= 1 && $form->submitter >= 0 ) {
			$form->error = "Usted ya ha completado la evaluación de los docentes del 1er Ciclo, usted no podrá llenar más!!!";

	/* Here is where I need to enabled ''btn_finalizar'' button
}
}	

Open in new window


so, if user has submit more than 2 form, he is redirect to a specific page and the error message is displayed, and at same time I need to enabled ''btn_finalizar'' button.(this is what I need).
The ''btn_finalizar'' is not the default submit button, this is another submit button that allow me redirect users to different pages.
Tnks

0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 34962922
similarly only

<input type="button" id="btn1" disabled="true"/>
0
 
LVL 1

Author Comment

by:plus_ec
ID: 34963111
Ok, Thanks, but sorry,
This is not what I need, As i said I need to disable button after the ''if'' sentence is done. Or better said, I need to disable button when the sentence is done.
The button by default is enabled on pageload, so, what I need is to disable button after the php code has done his job after ''if'' sentence.
I'm working on joomla, specifically with smartformer gold plugin. This plugin allow to design form with drag and drop, and allow to insert php, javascript and html code, but these code works in different windows.
0
 
LVL 40

Accepted Solution

by:
gurvinder372 earned 500 total points
ID: 34963140
ok, then

<script>
  document.getElementById("btn1").disabled = "true";
</script>
0
 
LVL 1

Author Comment

by:plus_ec
ID: 34963312
Thanks, but, Actually, I was trying this from the beginning, but not working.
Is as if javascript do not load inside php code, after ''if'' sentence. I don't know why?
0
 
LVL 27

Expert Comment

by:Lukasz Chmielewski
ID: 34963478
Try switching
<script language="javascript">
to
<script type="text/javascript">
0
 
LVL 40

Expert Comment

by:gurvinder372
ID: 34963488
it will work, i am using getElementById, not getElementsByName like you.

Please try the same
0
 
LVL 1

Author Comment

by:plus_ec
ID: 34963740
Roads_Roads
I'm was trying to switching the tags, but it's do not work.

gurvinder372
From beginning I added id tag to buttons to use different ways, including yours, but it's do not work.

Another suggestions?
0
 
LVL 1

Assisted Solution

by:plus_ec
plus_ec earned 0 total points
ID: 34994353
For an unknow reason, the smartformer plugin does not allow to insert javacript code inside php code, so, I did the following:
As you can see in this code I restrict form submissions.
$form->data['user_id'] = &JFactory::getUser()->id;
$db_name =  $form->formXMLStruct['database']['name'];
$query = "select count(id) from $db_name where user_id={$form->data['user_id']}";
$database = &JFactory::getDBO();
$database->setQuery($query);
$res = $database->loadResult();
if ($res == null) die($query);
echo "<input type='text' id='res' name='res' value='{$res}' readonly='readonly' style='position:absolute; width:15px; height:16px; font-size:10px; visibility: hidden;'>";  

$username = $_POST['curso_boxmax'];
	if ($username == "1er Ciclo") {
		if ($res >= 8 && $form->submitter >= 0 ) {
		$form->page = 2;
		$form->error = "error message here!!!";
		}
}		

Open in new window

In the "echo", the variable $res, I put the value in a texbox with HTML code.
And in the javascript windows I did the following:
 I get the value of the variable $rest, and if $res==8, this are number of form submission, I disable button.
var n1 = document.getElementById("res");
if (n1.value == "7"){
document.getElementById("btn_finalizar").disabled = "true";
alert("error message here");
}
}

Open in new window

Thanks all for help, all you answers were Ok, but, the problem is in the plugin.
No one could answer my question in smartformer gold plugin, so, I can't divide Point, because no one reply was addressed to my question in joomla.
0
 
LVL 1

Author Closing Comment

by:plus_ec
ID: 35034690
No one could answer my question in smartformer gold plugin, so, I can't divide Point, because no one reply was addressed to my question in joomla.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

742 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question